// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Resource.java

package com.kaylyn.util;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

public class Resource
{

    public Resource()
    {
    }

    public static void playAudio(String fileName)
    {
        try
        {
            InputStream inputStream = Resource.class.getResourceAsStream("res/"+fileName);
            AudioStream audio = new AudioStream(new BufferedInputStream(inputStream));
            AudioPlayer.player.start(audio);
        }
        catch(FileNotFoundException e)
        {
            e.printStackTrace();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }

    public static BufferedImage loadBufferedImage(String fileName, Dimension dimension)
    {
        InputStream inputStream = Resource.class.getResourceAsStream("res/"+fileName);
        BufferedImage img = new BufferedImage(dimension.width, dimension.height, 2);
        try
        {
            BufferedImage src = ImageIO.read(new BufferedInputStream(inputStream));
            inputStream.close();
            Graphics g = img.getGraphics();
            g.drawImage(src, 0, 0, img.getWidth(), img.getHeight(), null);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
        return img;
    }

    public static Image loadImage(String fileName)
    {
        java.net.URL imageURL = Resource.class.getResource("res/"+fileName);
        Image img = (new ImageIcon(imageURL)).getImage();
        return img;
    }

    public static InputStream loadFile(String fileName)
    {
        return Resource.class.getResourceAsStream("res/"+fileName);
    }
}
